<?php 
    session_start();
    echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];
?>

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
       <link rel="stylesheet" href="styles/layout.css" type="text/css"/>
        <link rel="stylesheet" href="styles/computer.css" type="text/css"/>
        <script type="text/javascript" src="scripts/computer.js"></script>
        
    </head>
    <body>
        <?php
        require 'header.html';
        ?>
<div id="container">
  <div class="wrapper">
    <div id="content">
    	<div id="order">         
        <?php
        // put your code here
        if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "seller")){
        
        $categoryID = $_POST["categoryID"];
            if(strlen($categoryID) == 0){
                //add a new product
                echo "<h2>Add a new category</h2>";
            }else{
                echo "<h2>Change selected category</h2>";
                $con = mysql_connect("localhost", "zhouzhao", "19831022");
                if(!$con){
                    die("could not connect to DB: ".mysql_error());
                }
                
                mysql_select_db("cloudcom", $con);
                $result = mysql_query("select * from categories where categoryID = $categoryID");
                $row = mysql_fetch_assoc($result);
                
                mysql_close($con);
            }
        ?>
        
        
        <form method="post" action="commitCategory.php">
            
            <p>Category ID: <input type="text" name="categoryID" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($categoryID) != 0){
                             echo "value='".$row["categoryID"]."'";
                         }
                         ?>
                         /></p>
            <p>Category Name: <input type="text" name="categoryName" maxlength="20" class="rightAlign"
                         <?php
                         if(strlen($categoryID) != 0){
                             echo "value='".$row["categoryName"]."'";
                         }
                         ?>
                         /></p>
        Category Description: <textarea rows="3" cols="22" name="categoryDescription" maxlength="50"
                         >            
                                     <?php
                         if(strlen($categoryID) != 0){
                             echo $row["categoryDescription"];
                         }
                         ?>
        </textarea><br/>
        <input type="submit" name="button" value="Commit category" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        <input type="submit" name="button" value="Cancel" class="buttonStyle" onmouseover="changeOn(this)" onmouseout="changeOff(this)"/>
        </form>
        
        <?php }else{
                require 'login.html';
        }
        ?>
       </div>	
    </div>
    <br class="clear" />
  </div>
</div>
        <?php
        require 'tail.html';
        ?>
    </body>
</html>
